/*
 * author      : dormi330
 * date        : 2018/6/26
 * project     : mybatis
 * description : adaptor 商品服务
 */

package com.deep.trade.adaptor.required.sku;

import com.deep.trade.adaptor.required.IdService;
import com.deep.trade.adaptor.required.catalog.Catalog;
import com.deep.trade.application.AppRuntimeEvn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ItemSkuServiceMock implements ItemSkuService {

    private AppRuntimeEvn appRuntimeEvn;
    private Logger logger = LoggerFactory.getLogger(this.getClass().getName());
    private Map<String, Sku> itemSkuMap = new HashMap<>();

    @Autowired
    public ItemSkuServiceMock(AppRuntimeEvn appRuntimeEvn) {
        this.appRuntimeEvn = appRuntimeEvn;
    }


    public Sku skuOfId(String skuId) throws Exception {
        // String tenantCode = appRuntimeEvn.getTenantCode();
        return itemSkuMap.get(skuId);
    }

    public List<Sku> skuOfIds(List<String> skuIdList) throws Exception {
        // String tenantCode = appRuntimeEvn.getTenantCode();
        return skuIdList.stream()
                .map(skuId -> itemSkuMap.get(skuId))
                .collect(Collectors.toList());
    }

    public static Sku sku1 = new Sku(
            IdService.TENANT_CODE,
            IdService.SKU_1_ID,
            IdService.SELLER_1_ID,
            "seller1",
            IdService.SHOP_1_ID,
            IdService.ITEM_1_ID,
            "item_name_1",
            "item_code_1",
            IdService.BRAND_ID,
            IdService.SKU_1_CODE,
            new BigDecimal("100"),
            "https://www.baidu.com/img/bd_logo1.png",
            "color",
            "white",
            new BigDecimal("0.05"));

    public static Sku sku2 = new Sku(
            IdService.TENANT_CODE,
            IdService.SKU_2_ID,
            IdService.SELLER_1_ID,
            "seller1",
            IdService.SHOP_1_ID,
            IdService.ITEM_1_ID,
            "item_name_1",
            "item_code_1",
            IdService.BRAND_ID,
            IdService.SKU_2_CODE,
            new BigDecimal("100"),
            "https://www.baidu.com/img/bd_logo1.png",
            "color",
            "white",
            new BigDecimal("0.05"));

    private static Sku sku3 = new Sku(
            IdService.TENANT_CODE,
            IdService.SKU_3_ID,
            IdService.SELLER_2_ID,
            "seller2",
            IdService.SHOP_2_ID,
            IdService.ITEM_2_ID,
            "item_name_2",
            "item_code_2",
            IdService.BRAND_ID,
            IdService.SKU_3_CODE,
            new BigDecimal("100"),
            "https://www.baidu.com/img/bd_logo1.png",
            "color",
            "white",
            new BigDecimal("0.05"));

    private static Sku sku4 = new Sku(
            IdService.TENANT_CODE,
            IdService.SKU_4_ID,
            IdService.SELLER_2_ID,
            "seller2",
            IdService.SHOP_2_ID,
            IdService.ITEM_2_ID,
            "item_name_2",
            "item_code_2",
            IdService.BRAND_ID,
            IdService.SKU_4_CODE,
            new BigDecimal("100"),
            "https://www.baidu.com/img/bd_logo1.png",
            "color",
            "white",
            new BigDecimal("0.05"));

    @PostConstruct
    public void init() {
        itemSkuMap.put(sku1.getId(), sku1);
        itemSkuMap.put(sku2.getId(), sku2);
        itemSkuMap.put(sku3.getId(), sku3);
        itemSkuMap.put(sku4.getId(), sku4);
        logger.warn("ItemService 初始化, 添加测试数据 ");
    }
}
